package com.visionapps.demo.swipe.fragment;

import com.hackdf.ecographic.Parser;
import com.hackdf.ecographic.R;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Fragment to manage the central page of the 5 pages application navigation (top, center, bottom, left, right).
 */



public class CentralFragment extends Fragment {

	// -----------------------------------------------------------------------
	//
	// Methods
	//
	// -----------------------------------------------------------------------
	
	private String url = "http://datos.labplc.mx/aire.json";
	private Parser obj;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View fragmentView = inflater.inflate(R.layout.fragment_central, container, false);
		
		new AsyncWork().execute();

		return fragmentView;
	}
	
	public class AsyncWork extends AsyncTask<Void, Void, Void>{

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			
			obj = new Parser(url);
		}
		
		@Override
		protected Void doInBackground(Void... arg0) {
			
			obj.fetchJSON();
			
			return null;
		}
		
		@Override
		protected void onPostExecute(Void result) {
			super.onPostExecute(result);
			
			Log.i("result:", obj.getCategoria() + " " + obj.getColor() + " " + obj.getColoUV() + " " + obj.getCondicion() + " " + obj.getIndice()
					+ " " + obj.getRecomendaciones() + " " + obj.getRecomendaciones_uv() + " " + obj.getTemperatura());
		}
		
	}
}
